/**
 * Author(s): xuming.Wong <xuming.Wong@gmail.com>
 */
#ifndef __MAP_TILE_MANAGER_H__
#define __MAP_TILE_MANAGER_H__

#include "MapTile.h"
#include "OgreTerrain.h"
#include "OgreTerrainGroup.h"

namespace PQGame
{
	/*Mainly schedule map tiles.
	*/
	class MapTileManager
	{
	public:
		static const int TILE_MAX=64;
		static const int TILE_VERTICES=16*8+1;//A map tile is split up into 16x16 = 256 map chunks
		static const int TILE_WORLD_SIZE=TILE_SIZE;
		typedef std::map<int,MapTile*> MapTileMap;

		inline bool oktile(int i, int j)
		{
			return i>=0 && j >= 0 && i<64 && j<64;
		}

		MapTileManager(int index);
		
		MapTile* loadTile(int col, int row);
		MapTile* enterTile(int col, int row);

		void update(float deltaT);
	private:
		void initData();
		void initTerrain();
		void initTileTerrain(MapTile* tile);
		
	private:
		MapTileMap _tiles;
		int _index;
		int _mapCount;
		int _row;
		int _col;//current col in
		bool _outBound;
		bool _hasTile[64][64];//A world contains 64*64 map tiles
		unsigned int *_miniMap;

		MapTile* _tile;//current tile

		Ogre::TerrainGlobalOptions* _terrainGlobalOptions;
		Ogre::TerrainGroup* _terrainGroup;
	};
}

#endif
